/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Reportes;
//librerias Reportes
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.*;
import net.sf.jasperreports.view.save.JRPdfSaveContributor.*;
import net.sf.jasperreports.view.JRViewer.*;
import net.sf.jasperreports.view.save.JRMultipleSheetsXlsSaveContributor.*;


public class Report {
    
    
    
        public static final String DRIVER="com.mysql.jdbc.Driver";
        public static final String RUTA="jdbc:mysql://localhost/bufete";
        public static final String USER="root";
        public static final String PASSWORD="1234";
	public static Connection CONEXION;

   
    
    public void ReporteEstudiante(String nCarne){

        try{
            Class.forName(DRIVER);
            CONEXION = DriverManager.getConnection(RUTA,USER,PASSWORD);
            if(nCarne.isEmpty())
            {
                String plantilla="Reportes/StudentAll.jasper";
                JasperReport reporte=null;
                reporte=(JasperReport) JRLoader.loadObject(plantilla);
                
                Map param=new HashMap();
                JasperPrint jasperprint= JasperFillManager.fillReport(reporte,param,CONEXION);
                JasperViewer visor=new JasperViewer(jasperprint,false);
                visor.setTitle("Bufete Reportes - URL");
                visor.setVisible(true);
                
            }
            else{
               String plantilla="Reportes/Estudiante.jasper";
                JasperReport reporte=null;
                reporte=(JasperReport) JRLoader.loadObject(plantilla);
                
                Map param=new HashMap();
                param.put("nCarne",nCarne.trim() );
                JasperPrint jasperprint= JasperFillManager.fillReport(reporte,param,CONEXION);
                JasperViewer visor=new JasperViewer(jasperprint,false);
                visor.setTitle("Bufete Reportes - URL");
            visor.setVisible(true);
                

}

        }catch(Exception e){
            javax.swing.JOptionPane.showMessageDialog(null, e);

        }
    }
    
     public void ReporteCliente(String idCliente){

         try{
            Class.forName(DRIVER);
            CONEXION = DriverManager.getConnection(RUTA,USER,PASSWORD);
            if(idCliente.isEmpty())
            {
                String plantilla="Reportes/StudentAll.jasper";
                JasperReport reporte=null;
                reporte=(JasperReport) JRLoader.loadObject(plantilla);
                
                Map param=new HashMap();
                JasperPrint jasperprint= JasperFillManager.fillReport(reporte,param,CONEXION);
                JasperViewer visor=new JasperViewer(jasperprint,false);
                visor.setTitle("Bufete Reportes - URL");
                visor.setVisible(true);
                
            }
            else{
               String plantilla="Reportes/Estudiante.jasper";
                JasperReport reporte=null;
                reporte=(JasperReport) JRLoader.loadObject(plantilla);
                
                Map param=new HashMap();
                param.put("IdClientes",idCliente.trim() );
                JasperPrint jasperprint= JasperFillManager.fillReport(reporte,param,CONEXION);
                JasperViewer visor=new JasperViewer(jasperprint,false);
                visor.setTitle("Bufete Reportes - URL");
            visor.setVisible(true);
                

}

        }catch(Exception e){
            javax.swing.JOptionPane.showMessageDialog(null, e);

        }

    }
    
    public void ReporteAsesor(String idAsesor){

        try{
            Class.forName(DRIVER);
            CONEXION = DriverManager.getConnection(RUTA,USER,PASSWORD);
            
            String plantilla="Reportes/Asesor.jasper";
            JasperReport reporte=null;
            reporte=(JasperReport) JRLoader.loadObject(plantilla);

            Map param=new HashMap();
            param.put("AsesorId",idAsesor );

            JasperPrint jasperprint= JasperFillManager.fillReport(reporte,param,CONEXION);
            JasperViewer visor=new JasperViewer(jasperprint,false);
            visor.setTitle("Bufete Reportes - URL");
            visor.setVisible(true);
//           



        }catch(Exception e){
            javax.swing.JOptionPane.showMessageDialog(null, e);

        }
    }
    
    public void Caso(String nCarne, String idCliente){

        try{
            Class.forName(DRIVER);
            CONEXION = DriverManager.getConnection(RUTA,USER,PASSWORD);
          
            String plantilla="Reportes/Casos.jasper";
            JasperReport reporte=null;
            reporte=(JasperReport) JRLoader.loadObject(plantilla);

            Map param=new HashMap();
            param.put("nCarne",nCarne );
            param.put("ClienteId",idCliente);

            JasperPrint jasperprint= JasperFillManager.fillReport(reporte,param,CONEXION);
            JasperViewer visor=new JasperViewer(jasperprint,false);
            visor.setTitle("Bufete Reportes - URL");
            visor.setVisible(true);
//            



        }catch(Exception e){
            javax.swing.JOptionPane.showMessageDialog(null, e);

        }
    }
    
    
    
}
